import util from '../../common/js/util'
import NProgress from 'nprogress'
import axios from 'axios';
import address from "../../../models/dict/address"
import moment from 'moment'
import dContract from '../../../models/dict/dContract';

export default {
    data() {
        return {
            contractList: [],
            currObj: {}


        }
    },
    methods: {
        //性别显示转换
        getContract: function () {


            if (this.contractId == "" || this.currObj == null) {
                this.currObj = dContract.fmtContract();
                return
            }
            axios.post("/a", {
                class: "contract",
                para: "getContract",
                j: {
                    _id: this.contractId
                }

            }).then((res) => {

                if (!res.data.class) {
                    res.data.class = [];

                }

                this.currObj = dContract.fmtContract(res.data.info)
                this.ShowSave = true;

            });

        },
        saveContract: function () {

            //     this.currObj.address = address.addressObj(this.selectedOptions, this.currObj.address.memo);

            axios.post("/a", {
                class: "contract",
                para: "saveContract",
                j: this.currObj

            }).then((res) => {
                if (res.data.re == "ok") {
                    this.ShowSave = false;
                    this.$emit("saveContract", this.currObj)


                } else {
                    alert(JSON.stringify(res.data));
                }
            });


        }



    },
    props: [
        "contractId"
    ],


    mounted() {
        this.getContract();
    },
    watch: {
        contractId: function name(params) {



            console.log("contractId变动" + this.contractId);
            this.getContract();
        }
    }

}